import { fileURLToPath, URL } from 'node:url'

import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import Icons from 'unplugin-icons/vite'
import IconResolver from 'unplugin-icons/resolver'

import px2rem from "postcss-px2rem"
// https://vitejs.dev/config/
export default defineConfig({
  server: {
    proxy: {
      // 代理  http://localhost:8080/api/user/login
      '/api': {
        target: loadEnv('development', process.cwd()).VITE_APP_BASE_URL,
        changeOrigin: true
      }
    }
  },
  plugins: [
    vue(),
    AutoImport({
      imports: ['vue'],
      resolvers: [ElementPlusResolver(), IconResolver()]
    }),
    Components({
      resolvers: [
        ElementPlusResolver(),
        IconResolver({
          enabledCollections: ['ep']
        })
      ]

    }),
    Icons({
      autoInstall: true,
    }),
  ],

  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  
 
//  css: {
//       postcss: {
//           plugins: [
//             px2rem({
//               remUnit:192
//             })
//           ]
//       }
//   }

})
